#include "ROSyncCreation.h"
#include "QQuickROData.h"
#include "ROHost.h"
#include "RONode.h"
ROSyncCreation::ROSyncCreation(QObject *parent):ROSyncObject(parent)
{

}

void ROSyncCreation::initialize()
{
    ROSyncObject::initialize();
}

void ROSyncCreation::registerObject(QObject *obj, const QStringList &reason)
{
    auto data = getROObjectData(this);
    if(data)
    {
        QStringList reason__ = {"syncObj",QString::number(data->id)};
        reason__.append(reason);
        data->host->registerObject(obj,reason__);
    }
}

void ROSyncCreation::registerObjectIndividual(QObject *obj)
{
    auto objs = obj->findChildren<QObject*>();
    objs.prepend(obj);
    for(auto i :objs)
    {
        auto sync = qobject_cast<ROSyncObject*>(i);
        if(sync)
        {
            sync->initialize();
        }
    }
}

QObject *ROSyncCreation::getObjectById(int id)
{
    auto data = getROObjectData(this);

    if(data)
    {
        if(data->host)
        {

        }
        else if(data->node)
        {
            return data->node->getObjectById(id);
        }
    }

    return nullptr;
}
